#!../../bin/linux-x86_64/llrfCond

## You may have to change llrfCond to something else
## everywhere it appears in this file

< envPaths

cd "${TOP}"

## Register all support components
dbLoadDatabase "dbd/llrfCond.dbd"
llrfCond_registerRecordDeviceDriver pdbbase

## Load record instances

# Load autoSave database
dbLoadRecords("$(AUTOSAVE)/db/save_restoreStatus.db", "P=llrfCond:")

# Load CM database files (CM1-CM6)
dbLoadRecords("db/CM1.db", "P=iLinac-CM01,P1=iLinac-CM01:LLRF-01,P2=iLinac-CM01:LLRF-02,P3=iLinac-CM01:LLRF-03,P4=iLinac-CM01:LLRF-04,P5=iLinac-CM01:LLRF-05")
dbLoadRecords("db/CM2.db", "P=iLinac-CM02,P1=iLinac-CM02:LLRF-01,P2=iLinac-CM02:LLRF-02,P3=iLinac-CM02:LLRF-03,P4=iLinac-CM02:LLRF-04,P5=iLinac-CM02:LLRF-05")
dbLoadRecords("db/CM3.db", "P=iLinac-CM03,P1=iLinac-CM03:LLRF-01,P2=iLinac-CM03:LLRF-02,P3=iLinac-CM03:LLRF-03,P4=iLinac-CM03:LLRF-04,P5=iLinac-CM03:LLRF-05")
dbLoadRecords("db/CM4.db", "P=iLinac-CM04,P1=iLinac-CM04:LLRF-01,P2=iLinac-CM04:LLRF-02,P3=iLinac-CM04:LLRF-03,P4=iLinac-CM04:LLRF-04,P5=iLinac-CM04:LLRF-05")
dbLoadRecords("db/CM5.db", "P=iLinac-CM05,P1=iLinac-CM05:LLRF-01,P2=iLinac-CM05:LLRF-02,P3=iLinac-CM05:LLRF-03,P4=iLinac-CM05:LLRF-04,P5=iLinac-CM05:LLRF-05")
dbLoadRecords("db/CM6.db", "P=iLinac-CM06,P1=iLinac-CM06:LLRF-01,P2=iLinac-CM06:LLRF-02,P3=iLinac-CM06:LLRF-03,P4=iLinac-CM06:LLRF-04,P5=iLinac-LBQL06-RF:LLRF05")

# Load LBHL database files (CM7-CM17)
dbLoadRecords("db/CM7.db", "P=iLinac-LBHL01,P1=iLinac-LBHL01-RF:LLRF01,P2=iLinac-LBHL01-RF:LLRF02,P3=iLinac-LBHL01-RF:LLRF03,P4=iLinac-LBHL01-RF:LLRF04,P5=iLinac-LBHL01-RF:LLRF05,P6=iLinac-LBHL01-RF:LLRF06")
dbLoadRecords("db/CM8.db", "P=iLinac-LBHL02,P1=iLinac-LBHL02-RF:LLRF01,P2=iLinac-LBHL02-RF:LLRF02,P3=iLinac-LBHL02-RF:LLRF03,P4=iLinac-LBHL02-RF:LLRF04,P5=iLinac-LBHL02-RF:LLRF05,P6=iLinac-LBHL02-RF:LLRF06")
dbLoadRecords("db/CM9.db", "P=iLinac-LBHL03,P1=iLinac-LBHL03-RF:LLRF01,P2=iLinac-LBHL03-RF:LLRF02,P3=iLinac-LBHL03-RF:LLRF03,P4=iLinac-LBHL03-RF:LLRF04,P5=iLinac-LBHL03-RF:LLRF05,P6=iLinac-LBHL03-RF:LLRF06")
dbLoadRecords("db/CM10.db", "P=iLinac-LBHL04,P1=iLinac-LBHL04-RF:LLRF01,P2=iLinac-LBHL04-RF:LLRF02,P3=iLinac-LBHL04-RF:LLRF03,P4=iLinac-LBHL04-RF:LLRF04,P5=iLinac-LBHL04-RF:LLRF05,P6=iLinac-LBHL04-RF:LLRF06")
dbLoadRecords("db/CM11.db", "P=iLinac-LBHL05,P1=iLinac-LBHL05-RF:LLRF01,P2=iLinac-LBHL05-RF:LLRF02,P3=iLinac-LBHL05-RF:LLRF03,P4=iLinac-LBHL05-RF:LLRF04,P5=iLinac-LBHL05-RF:LLRF05,P6=iLinac-LBHL05-RF:LLRF06")
dbLoadRecords("db/CM12.db", "P=iLinac-LBHL06,P1=iLinac-LBHL06-RF:LLRF01,P2=iLinac-LBHL06-RF:LLRF02,P3=iLinac-LBHL06-RF:LLRF03,P4=iLinac-LBHL06-RF:LLRF04,P5=iLinac-LBHL06-RF:LLRF05,P6=iLinac-LBHL06-RF:LLRF06")
dbLoadRecords("db/CM13.db", "P=iLinac-LBHL07,P1=iLinac-LBHL07-RF:LLRF01,P2=iLinac-LBHL07-RF:LLRF02,P3=iLinac-LBHL07-RF:LLRF03,P4=iLinac-LBHL07-RF:LLRF04,P5=iLinac-LBHL07-RF:LLRF05,P6=iLinac-LBHL07-RF:LLRF06")
dbLoadRecords("db/CM14.db", "P=iLinac-LBHL08,P1=iLinac-LBHL08-RF:LLRF01,P2=iLinac-LBHL08-RF:LLRF02,P3=iLinac-LBHL08-RF:LLRF03,P4=iLinac-LBHL08-RF:LLRF04,P5=iLinac-LBHL08-RF:LLRF05,P6=iLinac-LBHL08-RF:LLRF06")
dbLoadRecords("db/CM15.db", "P=iLinac-LBHL09,P1=iLinac-LBHL09-RF:LLRF01,P2=iLinac-LBHL09-RF:LLRF02,P3=iLinac-LBHL09-RF:LLRF03,P4=iLinac-LBHL09-RF:LLRF04,P5=iLinac-LBHL09-RF:LLRF05,P6=iLinac-LBHL09-RF:LLRF06")
dbLoadRecords("db/CM16.db", "P=iLinac-LBHL10,P1=iLinac-LBHL10-RF:LLRF01,P2=iLinac-LBHL10-RF:LLRF02,P3=iLinac-LBHL10-RF:LLRF03,P4=iLinac-LBHL10-RF:LLRF04,P5=iLinac-LBHL10-RF:LLRF05,P6=iLinac-LBHL10-RF:LLRF06")
dbLoadRecords("db/CM17.db", "P=iLinac-LBHL11,P1=iLinac-LBHL11-RF:LLRF01,P2=iLinac-LBHL11-RF:LLRF02,P3=iLinac-LBHL11-RF:LLRF03,P4=iLinac-LBHL11-RF:LLRF04,P5=iLinac-LBHL11-RF:LLRF05,P6=iLinac-LBHL11-RF:LLRF06")

# Load CM APL database files (CM1-CM6)
dbLoadRecords("db/CM1_APL.db", "P=iLinac-CM01,P1=iLinac-CM01:LLRF-01,P2=iLinac-CM01:LLRF-02,P3=iLinac-CM01:LLRF-03,P4=iLinac-CM01:LLRF-04,P5=iLinac-CM01:LLRF-05")
dbLoadRecords("db/CM2_APL.db", "P=iLinac-CM02,P1=iLinac-CM02:LLRF-01,P2=iLinac-CM02:LLRF-02,P3=iLinac-CM02:LLRF-03,P4=iLinac-CM02:LLRF-04,P5=iLinac-CM02:LLRF-05")
dbLoadRecords("db/CM3_APL.db", "P=iLinac-CM03,P1=iLinac-CM03:LLRF-01,P2=iLinac-CM03:LLRF-02,P3=iLinac-CM03:LLRF-03,P4=iLinac-CM03:LLRF-04,P5=iLinac-CM03:LLRF-05")
dbLoadRecords("db/CM4_APL.db", "P=iLinac-CM04,P1=iLinac-CM04:LLRF-01,P2=iLinac-CM04:LLRF-02,P3=iLinac-CM04:LLRF-03,P4=iLinac-CM04:LLRF-04,P5=iLinac-CM04:LLRF-05")
dbLoadRecords("db/CM5_APL.db", "P=iLinac-CM05,P1=iLinac-CM05:LLRF-01,P2=iLinac-CM05:LLRF-02,P3=iLinac-CM05:LLRF-03,P4=iLinac-CM05:LLRF-04,P5=iLinac-CM05:LLRF-05")
dbLoadRecords("db/CM6_APL.db", "P=iLinac-CM06,P1=iLinac-CM06:LLRF-01,P2=iLinac-CM06:LLRF-02,P3=iLinac-CM06:LLRF-03,P4=iLinac-CM06:LLRF-04,P5=iLinac-LBQL01-RF:LLRF05")

# Load LBHL APL database files (CM7-CM17)
dbLoadRecords("db/CM7_APL.db", "P=iLinac-LBHL01,P1=iLinac-LBHL01-RF:LLRF01,P2=iLinac-LBHL01-RF:LLRF02,P3=iLinac-LBHL01-RF:LLRF03,P4=iLinac-LBHL01-RF:LLRF04,P5=iLinac-LBHL01-RF:LLRF05,P6=iLinac-LBHL01-RF:LLRF06")
dbLoadRecords("db/CM8_APL.db", "P=iLinac-LBHL02,P1=iLinac-LBHL02-RF:LLRF01,P2=iLinac-LBHL02-RF:LLRF02,P3=iLinac-LBHL02-RF:LLRF03,P4=iLinac-LBHL02-RF:LLRF04,P5=iLinac-LBHL02-RF:LLRF05,P6=iLinac-LBHL02-RF:LLRF06")
dbLoadRecords("db/CM9_APL.db", "P=iLinac-LBHL03,P1=iLinac-LBHL03-RF:LLRF01,P2=iLinac-LBHL03-RF:LLRF02,P3=iLinac-LBHL03-RF:LLRF03,P4=iLinac-LBHL03-RF:LLRF04,P5=iLinac-LBHL03-RF:LLRF05,P6=iLinac-LBHL03-RF:LLRF06")
dbLoadRecords("db/CM10_APL.db", "P=iLinac-LBHL04,P1=iLinac-LBHL04-RF:LLRF01,P2=iLinac-LBHL04-RF:LLRF02,P3=iLinac-LBHL04-RF:LLRF03,P4=iLinac-LBHL04-RF:LLRF04,P5=iLinac-LBHL04-RF:LLRF05,P6=iLinac-LBHL04-RF:LLRF06")
dbLoadRecords("db/CM11_APL.db", "P=iLinac-LBHL05,P1=iLinac-LBHL05-RF:LLRF01,P2=iLinac-LBHL05-RF:LLRF02,P3=iLinac-LBHL05-RF:LLRF03,P4=iLinac-LBHL05-RF:LLRF04,P5=iLinac-LBHL05-RF:LLRF05,P6=iLinac-LBHL05-RF:LLRF06")
dbLoadRecords("db/CM12_APL.db", "P=iLinac-LBHL06,P1=iLinac-LBHL06-RF:LLRF01,P2=iLinac-LBHL06-RF:LLRF02,P3=iLinac-LBHL06-RF:LLRF03,P4=iLinac-LBHL06-RF:LLRF04,P5=iLinac-LBHL06-RF:LLRF05,P6=iLinac-LBHL06-RF:LLRF06")
dbLoadRecords("db/CM13_APL.db", "P=iLinac-LBHL07,P1=iLinac-LBHL07-RF:LLRF01,P2=iLinac-LBHL07-RF:LLRF02,P3=iLinac-LBHL07-RF:LLRF03,P4=iLinac-LBHL07-RF:LLRF04,P5=iLinac-LBHL07-RF:LLRF05,P6=iLinac-LBHL07-RF:LLRF06")
dbLoadRecords("db/CM14_APL.db", "P=iLinac-LBHL08,P1=iLinac-LBHL08-RF:LLRF01,P2=iLinac-LBHL08-RF:LLRF02,P3=iLinac-LBHL08-RF:LLRF03,P4=iLinac-LBHL08-RF:LLRF04,P5=iLinac-LBHL08-RF:LLRF05,P6=iLinac-LBHL08-RF:LLRF06")
dbLoadRecords("db/CM15_APL.db", "P=iLinac-LBHL09,P1=iLinac-LBHL09-RF:LLRF01,P2=iLinac-LBHL09-RF:LLRF02,P3=iLinac-LBHL09-RF:LLRF03,P4=iLinac-LBHL09-RF:LLRF04,P5=iLinac-LBHL09-RF:LLRF05,P6=iLinac-LBHL09-RF:LLRF06")
dbLoadRecords("db/CM16_APL.db", "P=iLinac-LBHL10,P1=iLinac-LBHL10-RF:LLRF01,P2=iLinac-LBHL10-RF:LLRF02,P3=iLinac-LBHL10-RF:LLRF03,P4=iLinac-LBHL10-RF:LLRF04,P5=iLinac-LBHL10-RF:LLRF05,P6=iLinac-LBHL10-RF:LLRF06")
dbLoadRecords("db/CM17_APL.db", "P=iLinac-LBHL11,P1=iLinac-LBHL11-RF:LLRF01,P2=iLinac-LBHL11-RF:LLRF02,P3=iLinac-LBHL11-RF:LLRF03,P4=iLinac-LBHL11-RF:LLRF04,P5=iLinac-LBHL11-RF:LLRF05,P6=iLinac-LBHL11-RF:LLRF06")

# Load CM Data database files (CM1-CM6)
dbLoadRecords("db/CM1_Data.db", "P=iLinac-CM01,P1=iLinac-CM01:LLRF-01,P2=iLinac-CM01:LLRF-02,P3=iLinac-CM01:LLRF-03,P4=iLinac-CM01:LLRF-04,P5=iLinac-CM01:LLRF-05")
dbLoadRecords("db/CM2_Data.db", "P=iLinac-CM02,P1=iLinac-CM02:LLRF-01,P2=iLinac-CM02:LLRF-02,P3=iLinac-CM02:LLRF-03,P4=iLinac-CM02:LLRF-04,P5=iLinac-CM02:LLRF-05")
dbLoadRecords("db/CM3_Data.db", "P=iLinac-CM03,P1=iLinac-CM03:LLRF-01,P2=iLinac-CM03:LLRF-02,P3=iLinac-CM03:LLRF-03,P4=iLinac-CM03:LLRF-04,P5=iLinac-CM03:LLRF-05")
dbLoadRecords("db/CM4_Data.db", "P=iLinac-CM04,P1=iLinac-CM04:LLRF-01,P2=iLinac-CM04:LLRF-02,P3=iLinac-CM04:LLRF-03,P4=iLinac-CM04:LLRF-04,P5=iLinac-CM04:LLRF-05")
dbLoadRecords("db/CM5_Data.db", "P=iLinac-CM05,P1=iLinac-CM05:LLRF-01,P2=iLinac-CM05:LLRF-02,P3=iLinac-CM05:LLRF-03,P4=iLinac-CM05:LLRF-04,P5=iLinac-CM05:LLRF-05")
dbLoadRecords("db/CM6_Data.db", "P=iLinac-CM06,P1=iLinac-CM06:LLRF-01,P2=iLinac-CM06:LLRF-02,P3=iLinac-CM06:LLRF-03,P4=iLinac-CM06:LLRF-04,P5=iLinac-LBQL06-RF:LLRF05")

# Load LBHL Data database files (CM7-CM17)
dbLoadRecords("db/CM7_Data.db", "P=iLinac-LBHL01,P1=iLinac-LBHL01-RF:LLRF01,P2=iLinac-LBHL01-RF:LLRF02,P3=iLinac-LBHL01-RF:LLRF03,P4=iLinac-LBHL01-RF:LLRF04,P5=iLinac-LBHL01-RF:LLRF05,P6=iLinac-LBHL01-RF:LLRF06")
dbLoadRecords("db/CM8_Data.db", "P=iLinac-LBHL02,P1=iLinac-LBHL02-RF:LLRF01,P2=iLinac-LBHL02-RF:LLRF02,P3=iLinac-LBHL02-RF:LLRF03,P4=iLinac-LBHL02-RF:LLRF04,P5=iLinac-LBHL02-RF:LLRF05,P6=iLinac-LBHL02-RF:LLRF06")
dbLoadRecords("db/CM9_Data.db", "P=iLinac-LBHL03,P1=iLinac-LBHL03-RF:LLRF01,P2=iLinac-LBHL03-RF:LLRF02,P3=iLinac-LBHL03-RF:LLRF03,P4=iLinac-LBHL03-RF:LLRF04,P5=iLinac-LBHL03-RF:LLRF05,P6=iLinac-LBHL03-RF:LLRF06")
dbLoadRecords("db/CM10_Data.db", "P=iLinac-LBHL04,P1=iLinac-LBHL04-RF:LLRF01,P2=iLinac-LBHL04-RF:LLRF02,P3=iLinac-LBHL04-RF:LLRF03,P4=iLinac-LBHL04-RF:LLRF04,P5=iLinac-LBHL04-RF:LLRF05,P6=iLinac-LBHL04-RF:LLRF06")
dbLoadRecords("db/CM11_Data.db", "P=iLinac-LBHL05,P1=iLinac-LBHL05-RF:LLRF01,P2=iLinac-LBHL05-RF:LLRF02,P3=iLinac-LBHL05-RF:LLRF03,P4=iLinac-LBHL05-RF:LLRF04,P5=iLinac-LBHL05-RF:LLRF05,P6=iLinac-LBHL05-RF:LLRF06")
dbLoadRecords("db/CM12_Data.db", "P=iLinac-LBHL06,P1=iLinac-LBHL06-RF:LLRF01,P2=iLinac-LBHL06-RF:LLRF02,P3=iLinac-LBHL06-RF:LLRF03,P4=iLinac-LBHL06-RF:LLRF04,P5=iLinac-LBHL06-RF:LLRF05,P6=iLinac-LBHL06-RF:LLRF06")
dbLoadRecords("db/CM13_Data.db", "P=iLinac-LBHL07,P1=iLinac-LBHL07-RF:LLRF01,P2=iLinac-LBHL07-RF:LLRF02,P3=iLinac-LBHL07-RF:LLRF03,P4=iLinac-LBHL07-RF:LLRF04,P5=iLinac-LBHL07-RF:LLRF05,P6=iLinac-LBHL07-RF:LLRF06")
dbLoadRecords("db/CM14_Data.db", "P=iLinac-LBHL08,P1=iLinac-LBHL08-RF:LLRF01,P2=iLinac-LBHL08-RF:LLRF02,P3=iLinac-LBHL08-RF:LLRF03,P4=iLinac-LBHL08-RF:LLRF04,P5=iLinac-LBHL08-RF:LLRF05,P6=iLinac-LBHL08-RF:LLRF06")
dbLoadRecords("db/CM15_Data.db", "P=iLinac-LBHL09,P1=iLinac-LBHL09-RF:LLRF01,P2=iLinac-LBHL09-RF:LLRF02,P3=iLinac-LBHL09-RF:LLRF03,P4=iLinac-LBHL09-RF:LLRF04,P5=iLinac-LBHL09-RF:LLRF05,P6=iLinac-LBHL09-RF:LLRF06")
dbLoadRecords("db/CM16_Data.db", "P=iLinac-LBHL10,P1=iLinac-LBHL10-RF:LLRF01,P2=iLinac-LBHL10-RF:LLRF02,P3=iLinac-LBHL10-RF:LLRF03,P4=iLinac-LBHL10-RF:LLRF04,P5=iLinac-LBHL10-RF:LLRF05,P6=iLinac-LBHL10-RF:LLRF06")
dbLoadRecords("db/CM17_Data.db", "P=iLinac-LBHL11,P1=iLinac-LBHL11-RF:LLRF01,P2=iLinac-LBHL11-RF:LLRF02,P3=iLinac-LBHL11-RF:LLRF03,P4=iLinac-LBHL11-RF:LLRF04,P5=iLinac-LBHL11-RF:LLRF05,P6=iLinac-LBHL11-RF:LLRF06")

cd "${TOP}/iocBoot/${IOC}"

# Configure autoSave
set_savefile_path("./autosave")
set_requestfile_path("./autosave")
save_restoreSet_status_prefix("llrfCond:")
save_restoreSet_IncompleteSetsOk(1)
save_restoreSet_DatedBackupFiles(1)

# Restore saved values before record initialization
set_pass0_restoreFile("auto_positions.sav")
set_pass1_restoreFile("auto_settings.sav")

iocInit

# Start autoSave after iocInit
# CM1_Data.db PVs - saved every hour (3600 seconds)
create_monitor_set("auto_positions.req", 3600, "P1=iLinac-CM01:LLRF-01,P2=iLinac-CM01:LLRF-02,P3=iLinac-CM01:LLRF-03,P4=iLinac-CM01:LLRF-04,P5=iLinac-CM01:LLRF-05")
create_monitor_set("auto_settings.req", 3600, "P1=iLinac-CM01:LLRF-01,P2=iLinac-CM01:LLRF-02,P3=iLinac-CM01:LLRF-03,P4=iLinac-CM01:LLRF-04,P5=iLinac-CM01:LLRF-05")

# CM2_Data.db PVs - saved every hour (3600 seconds)
create_monitor_set("auto_positions.req", 3600, "P1=iLinac-CM02:LLRF-01,P2=iLinac-CM02:LLRF-02,P3=iLinac-CM02:LLRF-03,P4=iLinac-CM02:LLRF-04,P5=iLinac-CM02:LLRF-05")
create_monitor_set("auto_settings.req", 3600, "P1=iLinac-CM02:LLRF-01,P2=iLinac-CM02:LLRF-02,P3=iLinac-CM02:LLRF-03,P4=iLinac-CM02:LLRF-04,P5=iLinac-CM02:LLRF-05")

## Start any sequence programs
#seq sncllrfCond, "user=iocuser"
